﻿#region Header

/*
    This file is part of nDoctor Light

    NDoctor is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    NDoctor is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with NDoctor.  If not, see <http://www.gnu.org/licenses/>.
*/

#endregion Header

namespace Probel.Ldoc.ViewModels.ToolBoxes
{
    using System.Windows.Input;

    using Probel.Ldoc.Services.Dto;
    using Probel.Ldoc.Services.Services;
    using Probel.Mvvm.DataBinding;

    public class RenameRecordViewModel : BaseViewModel
    {
        #region Fields

        private readonly ICommand renameCommand;
        private readonly IPatientService Service;

        private RecordCardDto currentRecord;

        #endregion Fields

        #region Constructors

        public RenameRecordViewModel(IErrorService errorService, IPatientService service, RecordCardDto record, bool isAsync = true)
            : base(errorService, isAsync)
        {
            this.CurrentRecord = record;
            this.Service = service;
            this.renameCommand = new RelayCommand(this.Rename, this.CanRename);
        }

        #endregion Constructors

        #region Properties

        public RecordCardDto CurrentRecord
        {
            get { return this.currentRecord; }
            set
            {
                this.currentRecord = value;
                this.OnPropertyChanged(() => CurrentRecord);
            }
        }

        public ICommand RenameCommand
        {
            get { return this.renameCommand; }
        }

        #endregion Properties

        #region Methods

        private bool CanRename()
        {
            return this.CurrentRecord != null;
        }

        private void Rename()
        {
            this.Service.UpdateRecordName(this.CurrentRecord);
        }

        #endregion Methods
    }
}